package se.liu.johfa428.game.objects.intro;

import java.awt.Color;

import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.model.WorldGraphics;
import se.liu.oschi129.world.objects.WorldStaticObject;

/**
 * Creates an Object that is able to fade.
 * @author johfa428
 *
 */
public class ObjectWhiteSpace extends WorldStaticObject {

	private float opacity;
	private	Color color;
	private double fadeSpeed;

	private boolean done = false;

	public ObjectWhiteSpace(double x, double y,double height, double width,double opacity, Color color, double fade) {
		super(x,y,width,height);
		setDepth(-2);
		this.color = color;
		this.opacity = (float)(opacity/100);	
		this.fadeSpeed = fade;
	}

	public ObjectWhiteSpace(double x, double y,double height,double width) {
		this(x,y,width,height, 100, Color.white, -2);
	}

	/**
	 * Sets the Opacity 
	 * @param opacity
	 * The Opacity value may only be a number inside the interval 0 - 100.
	 */
	public void setOpacity(double opacity){
		this.opacity = (float)(opacity/100);
	}

	public float getOpacity(){
		return this.opacity * 100;
	}

	public void setColor(Color color){
		this.color = color;
	}

	public Color getColor(){
		return this.color;
	}

	public boolean getDone(){
		return this.done;
	}

	public void setFadingSpeed (double fade){
		fadeSpeed = fade;
	}

	@Override public void performStepAction(World world) {

		double controll = getOpacity() + fadeSpeed;

		if (0 < controll && controll < 100){
			setOpacity(controll);	
		
		}
	}

	@Override 
	public void performDrawingAction(WorldGraphics worldg){

		worldg.setColor(getColor());	
		worldg.setAlpha((getOpacity()/100));
		worldg.fillRect((int) getX(),(int) getY(),(int) getWidth(),(int) getHeight());
		worldg.setAlpha(1);
	
	}
}



